#include <stdio.h>
#include <pthread.h>

char* data[5];	//names of people
int size = 0 ;	//number of people
pthread_mutex_t lock ; // 1

void* task(void *p)
{
	pthread_mutex_lock(&lock);  // 3
	data[size] = (char *)p;	    // 4
	usleep(100000);
	++size;
	pthread_mutex_unlock(&lock);// 5
}

int main()
{
	pthread_mutex_init(&lock,0); // 2
	pthread_t id,id2;
	data[size] = "zhaoyu";	
	++size;
	pthread_create(&id , 0 , task , "zhangfei");
	pthread_create(&id2 , 0 , task , "guanyu");
	pthread_join(id,0);
	pthread_join(id2,0);
	int i = 0;
	for( ; i < size ; ++i)
	{
		printf("%s\n",data[i]);
	}
	pthread_mutex_destroy(&lock); // 6
}
